/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sort;

/**
 *
 * @author Rodimiro
 */
//se importa la libreria necesaria

//Victor Fuentes      12176
//Yucely Beb          12537
//Roger Diaz          12298
//Rodimiro Castañeda  12122
import java.util.*;


public class InsertionSort {
    ArrayList <Integer> indice;//ArrayList de enteros
    int l;//largo del Array
    int identificador;//variable representante dle elemento correspondiente
    int temporal;//variable para asignacion
    int temporal2;//variable para asignacion
    int temp;//variable temporal
    int convertir;
    int agregar;
    public InsertionSort(){
        indice = new ArrayList <> ();//se instancia el ArrayList de enteros

    }   
        //algoritmo aplicado solamente con arraylist, sin embargo por causas desconocidas no funciono
        public static void insertionsort(ArrayList <String> listita) {
               // pre: 0 <= n <= data.length
               // post: values in data[0..n-1] are in ascending order
            ArrayList <Integer> indice = new ArrayList<>();
            ArrayList <String> lista00 = new ArrayList <>();
            int t1;
            int t2;
            int temporalito;
            int identificador; 
            lista00 = listita;
            int n =indice.size();
            int numSorted = 1; // number of values in place
            int index; // general index
            for (int g=0; g<lista00.size(); g++){
               identificador = Integer.parseInt(lista00.get(g));
               indice.add(g, identificador);
               //System.out.println(indice);
            }
            System.out.println(indice);
            n = indice.size();
            while (numSorted < n){
               
                 // take the first unsorted value
                 int temp = indice.get(numSorted);
                 // ...and insert it among the sorted:
                 for (index = numSorted; index > 0; index--){
                     if (temp < indice.get(index-1)){
                       //t1=  indice.get(index);
                       //t2 = indice.get(index-1);
                       //temporalito = t1;
                       //t1=t2;
                       //t2= temporalito;
                      indice.add(index, indice.get(index-1));
                      //System.out.println(t2);
                     // System.out.println(indice);
                     }
                     
                     else {
                              break;
                            }
                    }
                    // reinsert value 
                   //t1 = temp;
                    indice.add(index, temp);
                    numSorted++;
                    }
         System.out.println(indice);   
        }
        
        //metodo de insertioSort definitivo el cual es llamado por mainTemp
        public void insertionSort(ArrayList <String> list){
           ArrayList <String> listaM = new ArrayList <>();
           listaM = list;
           int[] enteros;
           int convertir;
           int agregar;
           int numeral = 1;
           int n = listaM.size();
           enteros = new int [n];
           
           System.out.println(listaM);
           for (int g = 0 ; g<listaM.size()-1; g++){
              convertir = Integer.parseInt(listaM.get(g));
              enteros[g] = convertir ;
              //System.out.println(enteros[g]);
           }
           int indice;
           while (numeral < n){
               int tempp = enteros[numeral];
               for (indice = numeral; indice > 0; indice--){
                   if (tempp < enteros [indice-1]){
                       enteros [indice] = enteros [indice-1];
                   } else{
                       break;
                   }
               }
               enteros [indice] = tempp;
               numeral++;
           }
         for (int h = 0; h<n; h++){
             System.out.println(enteros[h]);
             
         }
        }
        
       
}
    

